﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefPackageRecord" :model="statePackageRecord.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_PackageId_FormItem" prop="LinkedVM.PackageId" :label="$t('message.autotrans._Model_PackageRecord_Package')">
          <el-select v-model="statePackageRecord.vmModel.LinkedVM.PackageId" clearable>
             <el-option v-for="item in statePackageRecord.AllPackages" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_WoId_FormItem" prop="LinkedVM.WoId" :label="$t('message.autotrans._Model_PackageRecord_WoId')">
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.WoId" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_WoCode_FormItem" prop="LinkedVM.WoCode" :label="$t('message.autotrans._Model_PackageRecord_WoCode')">
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.WoCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ProductId_FormItem" prop="LinkedVM.ProductId" :label="$t('message.autotrans._Model_PackageRecord_ProductId')">
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.ProductId" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ProductName_FormItem" prop="LinkedVM.ProductName" :label="$t('message.autotrans._Model_PackageRecord_ProductName')">
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.ProductName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Sn_FormItem" prop="LinkedVM.Sn" :label="$t('message.autotrans._Model_PackageRecord_Sn')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_PackageRecord_Sn')}), trigger: 'blur' }]" >
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.Sn" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_PartSn_FormItem" prop="LinkedVM.PartSn" :label="$t('message.autotrans._Model_PackageRecord_PartSn')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_PackageRecord_PartSn')}), trigger: 'blur' }]" >
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.PartSn" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_StartTime_FormItem" prop="LinkedVM.StartTime" :label="$t('message.autotrans._Model_PackageRecord_StartTime')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_PackageRecord_StartTime')}), trigger: 'blur' }]" >
          <el-date-picker v-model="statePackageRecord.vmModel.LinkedVM.StartTime" type='date' clearable></el-date-picker>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Remark_FormItem" prop="LinkedVM.Remark" :label="$t('message.autotrans._Model_PackageRecord_Remark')">
          <el-input v-model="statePackageRecord.vmModel.LinkedVM.Remark" clearable></el-input>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitPackageRecord"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onClosePackageRecord"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PagePackageManagementPackageRecordBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { packagerecordApi } from '/@/api/packagemanagement/packagerecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefPackageRecord = ref();
const statePackageRecord = reactive({
    vmModel: {
	  LinkedVM:{
        PackageId: null,
        WoCode: '',
        ProductName: '',
        Sn: '',
        PartSn: '',
        StartTime: undefined,
        Remark: '',
      },
      Ids:[],
      
	},
    
    AllPackages: [] as any[],
});

// 取消
const onClosePackageRecord = () => {
    closeDialog();
};

// 提交
const onSubmitPackageRecord = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefPackageRecord.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            packagerecordApi().batchedit(statePackageRecord.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/PackageManagement/PackageRecord/GetPackageBanks',[],false).then(x=>{statePackageRecord.AllPackages = x});
    if (ci.attrs["wtmdata"]) {
		statePackageRecord.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		statePackageRecord.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

